import java.awt.Dimension;
import java.util.Scanner;


public class WallForce implements ApplyForce {
    
    
    private double magnitude=5 ;
    private double preMagnitude=5;
    private double exponent=0;
    private int wallID;
    private Simulation canvas;

   

    @Override
    public void turnOffForce () {
        magnitude=0;
        
    }

    @Override
    public void turnOnForce () {
        magnitude=preMagnitude;
        
    }

    @Override
    public void toggle () {
        if ( magnitude==0){
            turnOnForce();
        }else{
            turnOffForce();
        }
        
    }
    
    public void setWallID(int id){
        wallID=id;
    }
    
    public void setMagnitude(double mag){
        magnitude=mag;
        preMagnitude=magnitude;
    }
    
    public void setExponent(double expo){
        exponent=expo;
    }
    
    
    
    public Force getForce ( Mass m  ) {
        Dimension bounds=Simulation.getSize();
        double distance;
        double direction;
        if (wallID == 1) {
            // top
            distance = m.getCenter().getY();
            direction = 90;
        }
        else if (wallID == 2) {
            // right
            distance = bounds.getWidth() - m.getCenter().getX();
            direction = 180;
        }
        else if (wallID == 3) {
            // bottom
            distance = bounds.getHeight() - m.getCenter().getY();
            direction = 270;
        }
        else {
            // left
            distance = m.getCenter().getX();
            direction = 0;
        }
         magnitude = magnitude / Math.pow(distance, exponent);
        // System.out.println(distance);
        Force repulse = new Force(direction, magnitude);
        return repulse;
    }
    
    
    
    
    public void setSimulation(Simulation sim){
        canvas=sim;
    }

    @Override
    public void build (Scanner line, Simulation sim) {
        // TODO Auto-generated method stub
        
    }

   

}
